<script>
	export default {
		globalData: {
		           islogin: false,
							token:'',
							accessToken:'',
							fromid:'',
							swipers:[],
							mpuser:{id:''},
							dialogTitle:'山西交控科技转化平台',
							sys:'1', 
							isH5:false, 
							httpsUrl:'http://localhost:8080/jeecg-boot/',
							imgUrl:'http://localhost:8080/jeecg-boot/sys/common/static/',
							videoUrl:'https://video1.sxsfjy.com:8443',
							uploadAction:'http://localhost:8080/jeecg-boot/upload',
							HEADER: {
								'content-type': 'application/json',
								//#ifdef H5
								'Form-type': navigator.userAgent.toLowerCase().indexOf("micromessenger") !== -1 ? 'wechat' : 'h5',
								//#endif
								//#ifdef MP
								'Form-type': 'routine',
								//#endif
								//#ifdef APP-VUE
								'Form-type': 'app',
								//#endif
							} ,
							scorecfg:{},
							share:{
									title:'山西交控科技转化平台',
									path:'/pages/main/index?fromid=',
									imageUrl:'/static/share.jpg',
									desc:' ',
									content:' '
							       }
							 
							
		       },
			    methods: {
		// app.vue 或全局前置守卫
		checkLoginStatus:function() {
		  try {
		    const token = uni.getStorageSync('user_token');
		    const expireTime = uni.getStorageSync('expire_time');
		    const userInfo = uni.getStorageSync('user_info');
			
		    if (!token || !expireTime) {
		      // 无有效凭证，跳转登录
		      this.redirectToLogin();
		      return false;
		    }
		
		    // 检查是否过期
		    if (Date.now() > expireTime) {
		      // 清除过期凭证
		      uni.removeStorageSync('user_token');
			  uni.removeStorageSync('user_info');
		      uni.removeStorageSync('expire_time');
		      this.redirectToLogin();
		      return false;
		    }
		
		    console.log('登录状态有效');
		    return true;
		
		  } catch (error) {
		    console.error('读取缓存失败:', error);
		    this.redirectToLogin();
		    return false;
		  }
		},
		// 跳转登录页
		redirectToLogin:function() {
		  uni.redirectTo({
		    url: '/pages/main/login'
		  });
		}
		}
		,
		onLaunch: function() {
			   this.checkLoginStatus();
		},
		onShow: function() {
			
		},
		onHide: function() {
			
		}
		
		
	}
</script>

<style lang="scss">
	/*每个页面公共css */
	@import "@/uni_modules/uview-ui/index.scss";
	@import "common/demo.scss";
	
</style>
